<?php

class Core_Component_System_Model_Logging_Access extends Soul_Model_Entity_Base {
	
	protected $tableName = '{t}system_log_access';
	
	public function fill($data){
		parent::fill($data);
		$this->addData($this->getParameter());
		return $this->markNoChanged();
	}
	
	protected function insertSelf(){
	   	$fields = array();
    	$values = array();
    	$params = array();
    	foreach($this->getProperties() as $property){
    		if($property->getInsertable()){
    			$fields[] = '`'.$property->getName().'`';
    			$values[] = ':'.$property->getName().':'.$property->getParameterType();
    			$params[$property->getName()] = $property->convertToDb($this->getData($property->getName()));
    		}
    	}
    	$sql = 'INSERT DELAYED INTO `'.$this->getTableName().'` ('.implode(',', $fields).') VALUES ('.implode(',', $values).')';
    	$this->getDb()->setSql($sql, $params)->execute();
    	if($this->getIdProperty()->getIsIncrement()){
    		$this->setIdValue($this->getDb()->getInsertId());
    	}		
	}

    protected function initializeProperties(){
        $this->createProperty('id', 'string', TRUE);
        $this->createProperty('source_type', 'string')->setUpdateable(FALSE);
        $this->createProperty('source_id', 'string')->setUpdateable(FALSE);
        $this->createProperty('ip_address', 'string')->setUpdateable(FALSE);
        $this->createProperty('access_time', 'string')->setUpdateable(FALSE);
        $this->createProperty('referer', 'string')->setUpdateable(FALSE);
        $this->createProperty('parameter', 'serialize')->setUpdateable(FALSE);
    }
}